<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%
request.setCharacterEncoding("utf-8");
%>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

    <jsp:include page="../../common/meta/meta.jsp"></jsp:include>
    
    <!-- 引入页面css -->
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/static/pcsofangche/my/register/register.css" />
    <!-- 引入页面js -->
    <script src="${pageContext.request.contextPath}/static/pcsofangche/my/register/register.js" type="text/javascript" charset="utf-8"></script>


<div class="register_head">
	<div class="register_head_topone"></div>
	<div class="register_head_toptwo"></div>
	<div class="register_head_content"><jsp:include page="../../common/allhead/allhead.jsp"></jsp:include></div>
</div>
<div class="login_back" style="background: url(${pageContext.request.contextPath}/static/pcsofangche/my/login/img/login_all_big.png);background-position: center center;width: 100%;"></div>
<div class="container">
    <div class="row back">
        <div class="col-lg-12 col-md-12">
            <div class="userpsw">
                <div class="rejister">会员注册</div>
                <div class="phone">
                    <input type="text" placeholder="请输入中国大陆手机号" style="font-size:14px;text-indent:10px;color:grey;width: 330px;height: 40px;" id="phone" class="register_userpsw_input"/>
                </div>
                <div class="waring" id="phonewaring">该手机号已注册，请更换手机号或直接登陆</div>
                <div class="vcode">
                    <input type="text" placeholder="请输入右边图片验证码" style="font-size:14px;text-indent:10px;color:grey;width: 220px;height: 40px;" id="vcode" class="register_vcode_input"/>
                    <div class="vcodeimg">
                        <img src="${pageContext.request.contextPath}/meb/codeimg" id="vcodeimg" style="height: 40px;width:110px" onclick="changevcode()">
                    </div>
                </div>
                <div class="waring" id="vcodewaring">验证码错误，请重新输入</div>
                <div class="pcode">
                    <input type="text" placeholder="手机验证码" id="pcode" style="font-size:14px;text-indent:10px;color:grey;width: 220px;height: 40px;" class="register_pcode_input"/>
                    <input type="button" class="sendpcode" onclick="sendcode()" value="发送验证码"></input>
                </div>
                <div class="waring">手机验证码错误，请重新输入</div>
                <div class="password">
                    <input type="checkbox" id="psdflag" onclick="checkboxOnclick(this)">&nbsp;我要设置登陆密码
                </div>
                <div class="info">(如未设置登陆密码，可直接用手机验证码登陆)</div>
                <div class="psd" id="password">
                    <input type="password"  style="font-size:14px;text-indent:10px;color:grey;width: 330px;height: 40px;" placeholder="请输入密码" id="pswd" class="register_psd_input"><%--密码中文提示没做，用span覆盖--%>
                </div>
                <div class="submit" onclick="register()">
                    注&nbsp;&nbsp;&nbsp;&nbsp;册
                </div>
                <div class="register_info center-block">已有帐号，直接登录</div>
            </div>
        </div>

    </div>
</div>
<div class="register_foot"><jsp:include page="../../common/allfoot/allfoot.jsp"></jsp:include></div>
<div class="register_slide"><jsp:include page="../../common/allside/allside.jsp"></jsp:include></div>


<script>
    var pcheck="2";
    var vcheck="2";
    var rePhone="2";
    $(document).ready(function(){
    });


    //选择是否设置密码
    function checkboxOnclick(checkbox) {
        if (checkbox.checked == true) {
            $("#password").css('display','block');
            $(".submit").css('margin-top','20px');
        } else {
            $("#password").css('display','none');
            $(".submit").css('margin-top','50px');
        }
    }

    //点击验证码切换
    function changevcode(){
        console.log("123")
        var random=Math.random()
        console.log(random);
        $("#vcodeimg").attr('src',basePath+'/meb/codeimg?'+random);
    }
    //手机号失焦检测是否存在
    $("#phone").blur(function(){

        var phone=$("#phone").val();
        console.log(phone)
        $.ajax({
            url:basePath+'/meb/checkphone',
            data:{
                phone:phone
            },
            type:'post',
            dataType:'json',
            success:function(data){
                pcheck=data.code;
                if(data.code=="2"){
                    $("#phonewaring").css('display','block');
                    layer.msg("该手机号已注册，请更换手机号或直接登陆");
                    rePhone="2";
                }
                if(data.code=="1"){
                    $("#phonewaring").css('display','none');
                    rePhone="1";
                }
            },
            error:function(data){

            },
            complete:function (data) {

            }
        })

    });


    //点击发送手机验证码
    function sendcode() {
    	 var vcode=$("#vcode").val();
         $.ajax({
             url:basePath+'/meb/checkcode',
             data:{
                 code:vcode
             },
             type:'post',
             dataType:'json',
             success:function(data){
                 vcheck=data.code;
                 if(data.code=="2"){
                     $("#vcodewaring").css('display','block');
                     layer.msg("验证码错误，请重新输入");
                 }
                 if(data.code=="1"){
                     $("#vcodewaring").css('display','none');
                     SendPhoneCode();
                 }
             },
             error:function(data){

             },
             complete:function (data) {

             }
         })
    	
        
    }

    //注册
    function register() {
        var phone=$("#phone").val();
        var password=$("#pswd").val();
        var coed=$("#pcode").val();
        if(pcheck=='1'){
            $("#phonewaring").css('display','none');
            if(vcheck=='1'){
                $("#vcodewaring").css('display','none');
                $.ajax({
                     url:basePath+'/meb/login',
                     data:{
                         phone:phone,
                         password:password,
                         scode:phone
                     },
                     type:'post',
                     dataType:'json',
                     success:function(data){
                         if ( data.code == "1" ){
                            layer.alert("您已成功注册，欢迎光临搜房车!",{icon: 1,title:"温馨提示"},function () {
                                var url = basePath + '/loginsteptwo';
                                url = encodeURI(url);
                                url = encodeURI(url);
                                window.location.href = (url);
                            })
                         }else if(data.code == "2"){
                             layer.alert("请输入正确的验证码或密码",{icon: 2,title:"温馨提示"});
                         }else{
                             window.location.href = (basePath+"/index");
                         }
                     },
                     error:function(data){

                     },
                     complete:function (data) {

                     }
                })
            }else{
                $("#vcodewaring").css('display','block');
            }
        }else{
            $("#phonewaring").css('display','block');
        }
    }
</script>

